﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Assignment_2
{
    class PixelRectangleBottomLeft
    {
        #region Variables
        public VertexPositionColor[] vertices
        {
            get;
            set;
        }
        public short[] indices
        {
            get;
            set;
        }
        private Color c;

        /*public VertexBuffer mapVB
        {
            get { return mapVB; }
            set { mapVB = value; }
        }

        public IndexBuffer mapIB
        {
            get { return mapIB; }
            set { mapIB = value; }
        }*/

        public float z
        {
            get;
            set;
        }

        public float x
        {
            get;
            set;
        }

        public float y
        {
            get;
            set;
        }
        #endregion

        #region Constants
        private const int TR = 0;
        private const int TL = 1;
        private const int BR = 2;
        private const int BL = 3;
        // Is not used
        private const float maxZ = 1f;
        #endregion

        public PixelRectangleBottomLeft(Color c, float x, float y)
        {
            this.c = c;
            this.x = x;
            this.y = y;

            CalculateZ();
            InitVertices();
            InitIndices();

            //mapVB = new VertexBuffer(graphicsDevice, typeof(VertexPositionColor), vertices.Length, BufferUsage.WriteOnly);
            //mapIB = new IndexBuffer(graphicsDevice, typeof(short), indices.Length, BufferUsage.WriteOnly);

            //mapVB.SetData<VertexPositionColor>(vertices);
            //mapIB.SetData<short>(indices);
        }

        private void InitVertices()
        {
            vertices = new VertexPositionColor[4];

            vertices[TR] = new VertexPositionColor(new Vector3(x, y, z), c);
            vertices[TL] = new VertexPositionColor(new Vector3(-x, y, z), c);
            vertices[BR] = new VertexPositionColor(new Vector3(x, -y, z), c);
            vertices[BL] = new VertexPositionColor(new Vector3(-x, -y, z), c);

            /*vertices[TR] = new VertexPositionColor(new Vector3(1, 1, 0), Color.Black);
            vertices[TL] = new VertexPositionColor(new Vector3(-1, 1, 0), Color.Black);
            vertices[BR] = new VertexPositionColor(new Vector3(1, -1, 0), Color.Black);
            vertices[BL] = new VertexPositionColor(new Vector3(-1, -1, 0), Color.White);*/
        }

        private void InitIndices()
        {
            //6 vertices make up 2 triangles which make up our rectangle
            indices = new short[6];

            //Front triangle 1 (bottom portion) |\
            indices[0] = TL; //top left;
            indices[1] = BR; // bottom right;
            indices[2] = BL; // bottom left;

            //Front Triangle 2 (top portion) \|
            indices[3] = TL; // top left;
            indices[4] = TR; // top right;
            indices[5] = BR; // bottom right;
        }

        private void CalculateZ()
        {
            z = (c.R / 100) - (c.B / 100);
        }
    }
}
